package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Recompense;
import com.ruoyi.system.service.IRecompenseService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 慢病报销Controller
 *
 * @author moweiyu
 * @date 2021-05-21
 */
@Controller
@RequestMapping("/system/recompense")
public class RecompenseController extends BaseController
{
    private String prefix = "system/recompense";

    @Autowired
    private IRecompenseService recompenseService;

    @RequiresPermissions("system:recompense:view")
    @GetMapping()
    public String recompense()
    {
        return prefix + "/recompense";
    }

    /**
     * 查询慢病报销列表
     */
    @RequiresPermissions("system:recompense:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Recompense recompense)
    {
        startPage();
        List<Recompense> list = recompenseService.selectRecompenseList(recompense);
        return getDataTable(list);
    }

    /**
     * 导出慢病报销列表
     */
    @RequiresPermissions("system:recompense:export")
    @Log(title = "慢病报销", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Recompense recompense)
    {
        List<Recompense> list = recompenseService.selectRecompenseList(recompense);
        ExcelUtil<Recompense> util = new ExcelUtil<Recompense>(Recompense.class);
        return util.exportExcel(list, "慢病报销数据");
    }

    /**
     * 新增慢病报销
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存慢病报销
     */
    @RequiresPermissions("system:recompense:add")
    @Log(title = "慢病报销", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Recompense recompense)
    {
        return toAjax(recompenseService.insertRecompense(recompense));
    }

    /**
     * 修改慢病报销
     */
    @GetMapping("/edit/{medInfoId}")
    public String edit(@PathVariable("medInfoId") Long medInfoId, ModelMap mmap)
    {
        Recompense recompense = recompenseService.selectRecompenseById(medInfoId);
        mmap.put("recompense", recompense);
        return prefix + "/edit";
    }

    /**
     * 修改保存慢病报销
     */
    @RequiresPermissions("system:recompense:edit")
    @Log(title = "慢病报销", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Recompense recompense)
    {
        return toAjax(recompenseService.updateRecompense(recompense));
    }

    /**
     * 删除慢病报销
     */
    @RequiresPermissions("system:recompense:remove")
    @Log(title = "慢病报销", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recompenseService.deleteRecompenseByIds(ids));
    }
}
